﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FlatRedBall;
using ROMAP.Utilities;
using ROMAP.Enums;

namespace ROMAP.Entities
{
    public abstract class Entity : PositionedObject
    {
        #region Fields

        protected Vector2i _tilePosition;

        #endregion

        #region Constants

        protected static float    TILE_Z = Layer.Background.ToFloat();
        protected static int    TILE_DIM = 64;
        protected static float  TILE_PPU = SpriteManager.Camera.PixelsPerUnitAt(0);
        protected static float TILE_SIZE = TILE_DIM / TILE_PPU;

        #endregion

        #region Properties

        public virtual Vector2i TilePosition
        {
            get 
            {
                return _tilePosition; 
            }
            set 
            { 
                _tilePosition = value;
                float realX = value.X * TILE_SIZE;
                float realY = -value.Y * TILE_SIZE;

                this.X = realX;
                this.Y = realY;
            }
        }

        public virtual int TileX
        {
            get 
            {
                _tilePosition.X = (int)Math.Round(this.X / TILE_SIZE);
                return _tilePosition.X; 
            }
            set
            {
                this.RelativeX = -value * TILE_SIZE;
                _tilePosition.X = value;
            }
        }

        public virtual int TileY
        {
            get
            {
                _tilePosition.Y = (int)Math.Round(this.Y / TILE_SIZE);
                return _tilePosition.Y; 
            }
            set
            {
                this.RelativeY = value * TILE_SIZE;
                _tilePosition.Y = value;
            }
        }

        #endregion

        protected virtual void Initialize()
        {
            SpriteManager.AddPositionedObject(this);
        }

        public abstract void Activity();

        public virtual void Destroy()
        {
            SpriteManager.RemovePositionedObject(this);
        }

    }
}
